<?php
// +----------------------------------------------------------------------
// | author: thinkphp
// +----------------------------------------------------------------------

namespace app\api\controller;


use app\api\logic\IndexLogic;
use think\response\Json;


/**
 * index
 * Class IndexController
 * @package app\api\controller
 */
class IndexController extends BaseApiController
{


    public array $notNeedLogin = ['index', 'config', 'driverConfig', 'policy', 'decorate'];


    /**
     * @notes 首页数据
     * @return Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function index()
    {
        $result = IndexLogic::getIndexData();
        return $this->data($result);
    }


    /**
     * @notes 全局配置
     * @return Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function config()
    {
        $result = IndexLogic::getConfigData();
        return $this->data($result);
    }


    /**
     * @notes 全局配置
     * @return Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function driverConfig()
    {
        $result = IndexLogic::getConfigData();
        $result['tabbar'] = [
            [
                "name" => "首页",
                "selected" => "http://link.demo.com/uploads/images/20250508/20250508101640ce6a04311.png",
                "unselected" => "http://link.demo.com/uploads/images/20250508/202505081016369fbb00712.png",
                "link" => [
                    "path" => "/pages/index/index",
                    "name" => "首页",
                    "type" => "shop"
                ],
                "is_show" => 1,
            ],
            [
                "name" => "接单",
                "selected" => "http://link.demo.com/uploads/images/20250509/202505091122198afe95824.png",
                "unselected" => "http://link.demo.com/uploads/images/20250509/2025050911215559e186764.png",
                "link" => [
                    "path" => "/pages/order/order",
                    "name" => "接单",
                    "type" => "shop"
                ],
                "is_show" => 1,
            ],
            [
                "name" => "我的",
                "selected" => "http://link.demo.com/uploads/images/20250508/20250508101647edd387852.png",
                "unselected" => "http://link.demo.com/uploads/images/20250508/202505081016472e8365695.png",
                "link" => [
                    "path" => "/pages/user/user",
                    "name" => "我的",
                    "type" => "shop"
                ],
                "is_show" => 1,
            ]

        ];
        $result['style'] = array_merge( $result['style'],["cardBg" => "http://link.demo.com/uploads/images/20250509/202505091444149ba6d5748.png"]);
        return $this->data($result);
    }

    /**
     * @notes 政策协议
     * @return Json
     */
    public
    function policy()
    {
        $type = $this->request->get('type/s', '');
        $result = IndexLogic::getPolicyByType($type);
        return $this->data($result);
    }


    /**
     * @notes 装修信息
     * @return Json
     */
    public
    function decorate()
    {
        $id = $this->request->get('id/d');
        $result = IndexLogic::getDecorate($id);
        return $this->data($result);
    }


}